package com.graduation.interceptor;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Resource
    private UserInterceptor userInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 放行路径
        List<String> excludePath = new ArrayList<>();
        excludePath.add("/administrators/login");
        excludePath.add("/administrators/register");
        excludePath.add("/swagger-ui.html");
        excludePath.add("/swagger-resources/**");
        excludePath.add("/v2/api-docs/**");
        excludePath.add("/webjars/springfox-swagger-ui/**");


        // 鉴权路径
        List<String> authPath = new ArrayList<>();
//        authPath.add("/wanshibang/h5/information/rent/house/message/add");//发布租房
//        authPath.add("/wanshibang/h5/information/lost/article/add");//发布失物
//        authPath.add("/wanshibang/h5/information/help/other/add");//发布互帮
//        authPath.add("/wanshibang/h5/old/things/add/electronics");//发布旧物电子
//        authPath.add("/wanshibang/h5/old/things/add/furniture");//发布旧物家具
//        authPath.add("/wanshibang/h5/old/things/add/other");//发布旧物其他


        registry.addInterceptor(userInterceptor)
                .addPathPatterns(authPath)  //添加拦截path
                .excludePathPatterns(excludePath); // 排除无需拦截的路径
    }
}
